package com.wanbatv.wanba.jianshencao.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.wanbatv.wanba.jianshencao.R;
import com.wanbatv.wanba.jianshencao.util.AppUtil;
import com.wanbatv.wanba.jianshencao.util.Crypto;
import com.wanbatv.wanba.jianshencao.util.ProductInfo;
import com.wanbatv.wanba.jianshencao.util.UrlUtils;
import com.wanbatv.wanba.jianshencao.util.Util;
import com.wanbatv.wanba.jianshencao.utils.Product;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.util.HashMap;
import java.util.Map;

import cn.ffcs.itvpay.ItvPayTask;


public class OpenActivityAction implements View.OnClickListener {
	@SuppressWarnings("rawtypes")
	private Class activityClass;
	private Map<String, String> params;
	private Context context;

	private String mProductCode = null;
	private String mTranId = null;
	private boolean mNeedAuth = false;
	private Drawable mOrderPrimaryButtonBackground = null;
	private Drawable mOrderSecondaryButtonBackground = null;

	private View.OnClickListener mListener = null;
	private AlertDialog myDialog=null;

	JSONArray arr_zhifubao=null;
	String orderInfo=null;
	public OpenActivityAction(Context context, Class activityClass,
							  Map<String, String> params) {
		this.activityClass = activityClass;
		this.context = context;
		this.params = params;
	}

	public OpenActivityAction(Context context, Class activityClass) {
		this.activityClass = activityClass;
		this.context = context;
	}

	public OpenActivityAction setOrderPrimaryButtonBackground(Drawable drawable) {
		mOrderPrimaryButtonBackground = drawable;
		return this;
	}

	public Drawable getOrderPrimaryButtonBackground() {
		return mOrderPrimaryButtonBackground;
	}

	public OpenActivityAction setOrderSecondaryButtonBackground(Drawable drawable) {
		mOrderSecondaryButtonBackground = drawable;
		return this;
	}

	public Drawable getOrderSecondaryButtonBackground() {
		return mOrderSecondaryButtonBackground;
	}

	public OpenActivityAction setNeedAuth(boolean needAuth) {
		mNeedAuth = needAuth;
		return this;
	}

	public boolean isNeedAuth() {
		return mNeedAuth;
	}

	public OpenActivityAction setProductCode(String productCode) {
		mProductCode = productCode;
		return this;
	}

	public String getProductCode() {
		return mProductCode;
	}

	public OpenActivityAction setTranId(String tranId) {
		mTranId = tranId;
		return this;
	}

	public String getTranId() {
		return mTranId;
	}

	@Override
	public void onClick(final View v) {
		if (mListener != null) {
			mListener.onClick(v);
		}


	/*	if (LoginActivity.IS_DINGGOU) {
			Intent intent = new Intent(context, activityClass);

			if (params != null) {
				for (String str : params.keySet()) {
					intent.putExtra(str, params.get(str));
				}
			}
			context.startActivity(intent);
		} else {
			creatAlertDialog_tuichu();
		}*/
		Intent intent = new Intent(context, activityClass);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		if (params != null) {
			for (String str : params.keySet()) {
				intent.putExtra(str, params.get(str));
			}
		}
		context.startActivity(intent);

	}

	public OpenActivityAction setOnClickListener(View.OnClickListener l) {
		mListener = l;
		return this;
	}


}
